package com.thn.netty.chat.primitive;

/**
 * Packet type. Used (among other things) to find the Packet's encoder/decoder.
 * @author LiuYueHong
 */
public enum PacketType {
	CMD_FUNCTION_BASE(getIdx()),
	CMD_FUNCTION_LOGIN(getIdx()),
	CMD_FUNCTION_SUBSCIBE(getIdx()),
	CMD_FUNCTION_USERLOGOUT(getIdx()),
	CMD_FUNCTION_MESSAGE(getIdx()),
	CMD_FUNCION_FORCELOGOUT(getIdx()),
	CMD_FUNCTION_MSG_STATUS(getIdx()),
	CMD_FUNCTION_SET_PRESENCE(getIdx()),
	CMD_FUNCTION_PUSH(getIdx()),
	CMD_FUNCTION_SWITCH(getIdx())
    ; 
    static short sIndex=0x6099;
    private final short mId;
    static short getIdx(){
        return sIndex++;
    }
    PacketType(short aId) {
        mId = aId;
    }
    public short id() {
        return mId;
    }
    public static PacketType forType(short aId) {
        for (PacketType type : PacketType.values()) {
            if (type.mId == aId) {
                return type;
            }
        }
        throw new IllegalArgumentException("bad PacketType: " + aId);
    }
    @Override
    public String toString() {
        return super.toString() + "(" + mId + ")";
    }
}